<?php
if ($_SESSION['thanhvien'] == 1)
    {
?> 

<!--DOI TRANG THAI-->
<?php
if (isset($_GET['trangthai']))
{
    $trangthai = $_GET ['trangthai'];
    $donhang = $_GET ['donhang'];
    
    //echo $trangthai;
    $result=mysql_query("select * from donhang where donhangid=$donhang ");
    while ($row = mysql_fetch_array($result))
        {
            if ("$row[tinhtrang]" == 2) 
                $result2 = mysql_query("update donhang set tinhtrang = 3 where donhangid=$donhang;");
            else if ("$row[tinhtrang]" == 3)
                $result2 = mysql_query("update donhang set tinhtrang = 4 where donhangid=$donhang;");
            else $result2 = mysql_query("update donhang set tinhtrang = 2 where donhangid=$donhang;");
//            if ($result2)
//                    print '<h2>Thành công !</h2>';
        }
}
?>

<?php if (!isset($_GET['chitiet'])) { ?> 	

<!--HIEN THI DANH SACH DON HANG--> 

<table width="980" style="margin-top: 50px;" border='0px' bordercolor='white' cellspacing='0px' cellpadding='10px' style='border-collapse: collapse;' >
    <tr align="center" style='font-weight: bolder; background: pink;' height='40px' >
        <td width="30px"><strong>STT</strong></td>
        <td><strong>Tên đơn hàng</strong></td>
        <td width="50px"><strong>Ngày hẹn</strong></td>
        <td width="50px"><strong>Ngày trả</strong></td>
        <td width="150px"><strong>Tình trạng</strong></td>
        <td width="200px"><strong>Chú ý</strong></td>
    </tr>
<?php


$loop = mysql_query("select * from donhang order by ngaytra");
    $mau = 0;
    while ($row = mysql_fetch_array($loop))
        {
            if (("$row[tinhtrang]"<5) and ("$row[tinhtrang]">1))
                {
?>
    
    <tr style='<?php 
                if ("$mau" == 0)
                {
                    $mau = 1;
                    print "background-color: aqua;";    
                }
                else $mau = 0;
           ?>'>
        <td align="center"><?php print "$row[donhangid]"; ?></td>
        <td><a href="index.php?quanlysanxuat&module&chitiet&donhang=<?php print "$row[donhangid]"; ?> ">
            <?php print "$row[donvilam]"; ?></a></td>
        <td align="center"><?php $date = "$row[ngayki]";$d = getdate(strtotime($date));print $d['mday'].'-'.$d['mon'].'-'.$d['year'];?></td>
        <td align="center"><?php $date = "$row[ngaytra]";$d = getdate(strtotime($date));print $d['mday'].'-'.$d['mon'].'-'.$d['year'];?></td>
        <td align="center">
        <a href="index.php?quanlysanxuat&module&trangthai=<?php print "$row[tinhtrang]"; ?>&donhang=<?php print "$row[donhangid]"; ?>">
        
        <?php 
        if ("$row[tinhtrang]" == 2)        
            print "<img src='styles/gift.png'> Chờ sản xuất";
        if ("$row[tinhtrang]" == 3)        
            print "<img src='styles/edit.png'> Đang sản xuất";
        if ("$row[tinhtrang]" == 4)        
            print "Đã giao hàng";

             ?>
             </a>
             </td>
        <td align="center">
        <a href='index.php?module=chuy&sanxuat&donhang=<?php print "$row[donhangid]"; ?>'>
            <img src='styles/edit.png'/>
                <?php print "$row[chuy2]"; ?></a></td>
    </tr>    
  <?php }} ?>
</table>

<?php 
    }
    else 
    {
            include 'modules/sanxuat/chitietdonhang.php';        
    }

?> 


<?php } ?> 
